package com.qc31.comlib

import com.qc31.baselib.net.AppContext


object UrlUtil {

    var project: String = "gps-web"

    private var http: String = "http://"


    var mVideoHost: String = http + "106.14.186.44:9980"

    fun setVideoHost(videoHost: String) {
        val host = videoHost.split(":")
        val i = host[1].toInt() - 1
        mVideoHost = http + host[0] + ":" + i
    }

    private val buffer = StringBuffer()

    private fun baseHttp(): StringBuffer {
        buffer.setLength(0)
        return buffer.append(http).append(UserConstant.current_ip).append(":")
            .append(UserConstant.current_port)
    }

    private fun baseHost(): StringBuffer {
        return baseHttp().append("/").append(project)
    }

    /**
     * 获取指定平台得BaseAPI
     */
    fun newBase(ip: String, port: String): String {
        buffer.setLength(0)
        return buffer.append(http).append(ip).append(":").append(port).append("/")
            .append(project).append("/app/").toString()
    }

    //广告图
    fun getHomePicUrl(img: String): String {
        return baseHost().append("/login?img=").append(img).append("&cmpId=")
            .append(UserConstant.current_cmpId).toString()
    }

    //欢迎页
    fun getWelcomeUrl(): String {
        return baseHost().append("/login?img=app_load&cmpId=").append(UserConstant.current_cmpId)
            .toString()
    }

    //登录logo图
    fun getLoginLogoUrl(): String {
        return baseHost().append("/login?img=app_logo&cmpId=").append(UserConstant.current_cmpId)
            .toString()
    }

    //登录背景图
    fun getLoginBgUrl(): String {
        return baseHost().append("/login?img=app_logo_bg&cmpId=").append(UserConstant.current_cmpId)
            .toString()
    }

    //运输
    fun baseTransport(): String {
        return baseHost().append("/h5/mgr/").toString()
    }

    /**
     * 扩展地址
     */
    fun getLogoUrl() = baseHost().toString() + "/"


    private val videoToastMap = HashMap<String, String>()
    fun getToastMap(): HashMap<String, String> {
        if (videoToastMap.isEmpty()) {
            val videoToasts: Array<String> =
                AppContext.getAppContext().resources.getStringArray(R.array.video_toast)
            videoToastMap["-6"] = videoToasts[0]
            videoToastMap["-4"] = videoToasts[1]
            videoToastMap["-3"] = videoToasts[2]
            videoToastMap["-2"] = videoToasts[3]
            videoToastMap["-1"] = videoToasts[4]
            videoToastMap["1"] = videoToasts[5]
            videoToastMap["2"] = videoToasts[6]
            videoToastMap["3"] = videoToasts[7]
            videoToastMap["10"] = videoToasts[8]
            videoToastMap["11"] = videoToasts[9]
            videoToastMap["12"] = videoToasts[10]
            videoToastMap["13"] = videoToasts[11]
            videoToastMap["14"] = videoToasts[12]
            videoToastMap["15"] = videoToasts[13]
            videoToastMap["16"] = videoToasts[14]
            videoToastMap["17"] = videoToasts[15]
            videoToastMap["20"] = videoToasts[16]
            videoToastMap["66"] = videoToasts[17]
            videoToastMap["77"] = videoToasts[18]
            videoToastMap["21"] = videoToasts[19]
            videoToastMap["30"] = videoToasts[20]
            videoToastMap["31"] = videoToasts[21]
            videoToastMap["32"] = videoToasts[22]
            videoToastMap["33"] = videoToasts[23]
            videoToastMap["34"] = videoToasts[24]
            videoToastMap["35"] = videoToasts[25]
            videoToastMap["44"] = videoToasts[26]
            videoToastMap["43"] = videoToasts[27]
            videoToastMap["88"] = videoToasts[28]

        }
        return videoToastMap
    }

    /***************************************************************/
    fun newBase(): String {
        return baseHost().append("/app/").toString()
    }
}

object Keys {
    const val INTENT_CAR_VIDEOS: String = "Videos"

    //跳转相关
    const val INTENT_TITLE = "title"
    const val INTENT_DATA = "data"
    const val INTENT_OTHER = "other"
    const val INTENT_TYPE = "type"
    const val INTENT_CAR_ID = "carId"
    const val INTENT_ID = "id"
    const val INTENT_PLATE = "plate"
    const val INTENT_CAR_NAME = "carName"
    const val INTENT_TEAM_NAME = "teamName"
    const val INTENT_TEAM_ID = "teamId"
    const val INTENT_TEAM_NUM = "carNum"
    const val INTENT_ALARM_ID = "alarmId"
    const val INTENT_IS_VIDEO = "isVideo"
    const val INTENT_TIME = "startTime"
    const val INTENT_START_TIME = "start_time"
    const val INTENT_END_TIME = "end_time"

    const val LOGIN_TYPE_IP = "ip"
    const val LOGIN_TYPE_PORT = "port"
    const val LOGIN_TYPE_USERID = "userId"
    const val LOGIN_TYPE_USER = "user"
    const val LOGIN_TYPE_LOGIN = "login_type"
    const val LOGIN_TYPE_COLOR_ID = "color_id"
    const val LOGIN_TYPE_PWD = "password"
    const val LOGIN_APP_AD_LINK_1 = "appAdLink1"
    const val LOGIN_APP_AD_LINK_2 = "appAdLink2"
    const val LOGIN_APP_AD_LINK_3 = "appAdLink3"
    const val LOGIN_TYPE_CAR = "car"
    const val SETTING_ALARM = "setting_alarm"
    const val SETTING_ALARM_SHOW = "setting_alarm_show"
    const val SETTING_ARREARS = "setting_arrears"
    const val APP_CFG_HOME_SET = "app_cfg_home_set"
    const val KEY_HOME_SET = "homeSet"

    //标志
    const val HOST_LOGO = "KEY"

    //公司ID
    const val CMP_ID = "cmpId"

    //视频相关
    const val VIDEO = "videos"

    //选中平台的下标
    const val CACHE_LOGIN_INDEX = "login_index"

    //所有平台数据
    const val CACHE_LOGIN_USERS = "login_users"

}